package com.dianhun.es.controller;

import com.dianhun.es.server.DocServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;

/**
 * @author cyt
 * @create 2020-08-26 20:57
 */

@CrossOrigin
@RestController
public class Test {

    @Autowired
    private DocServer gateDoc;

    @GetMapping("/search/{key}/{pageNo}/{size}")
    public ArrayList<Map<String, Object>> search(
            @PathVariable("key") String key,
            @PathVariable("pageNo") Integer pageNo,
            @PathVariable("size") Integer size) throws IOException {

        ArrayList<Map<String, Object>> search = gateDoc.searchHigh(key, pageNo, size);
        return search;
    }

    @GetMapping("/index/{key}")
    public boolean index(@PathVariable("key") String key) throws IOException {
        boolean docList = gateDoc.getDocList(key);
        return docList;
    }
}
